// --------------------------------------------------------------------------
// 
//	Electro Rifle - (c) Schroding Cat
//	
//	Edited For Schism by Dreo
//
// --------------------------------------------------------------------------

Actor ElectroRifleUpgradeSpawner : CustomInventory
{
	scale 1.05
	radius 24
	height 24
	+FORCEXYBILLBOARD
	-COUNTITEM
	+INVENTORY.ALWAYSPICKUP
	Inventory.Amount 0
	Inventory.MaxAmount 99999
	Inventory.PickupSound "none"
	Inventory.PickupMessage "You got Electro Rifle Upgrade! (Slot 4)"
	States
	{
		Spawn:
			IRIF A -1
			Stop
			
		Pickup:
			TNT1 A 0 A_GiveInventory("Rifle", 1)
			TNT1 A 0 A_GiveInventory("ElectroRifle", 1)
			TNT1 A 0 A_GiveInventory("Clip2", 30)
			TNT1 A 1
			Stop
	}
}

ACTOR ElectroRifle : Rifle
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 41
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "Clip2"//"ClipElec"
	Weapon.AmmoType2 "ElecRifleAmmo"
	+WEAPON.CHEATNOTWEAPON
	+WEAPON.NOALERT
	+WEAPON.NOAUTOAIM
	+WEAPON.NOAUTOFIRE
	+Powered_Up
	Inventory.PickupSound "CLIPIN"
	Inventory.Pickupmessage "You've got the electro rifle!"
	Obituary "%o was shot down by %k's electro rifle."
	Scale 0.8
	tag "Electro Rifle"
	Inventory.ForbiddenTo Paladin, Sorcerer, Corvus
	Weapon.SisterWeapon Rifle
	States
	{
 	Spawn:
		IRIF A -1
		Stop

	Select:
		TNT1 A 0 A_Giveinventory("RifleSelected",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_Takeinventory("StartDualWield",1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		TNT1 A 0 A_Takeinventory("SwitchFlashlight",1)
		TNT1 A 0 A_Takeinventory("Taunting",1)
		TNT1 A 5
		TNT1 A 0 A_Raise
		Wait

	Deselect:
		TNT1 A 0 A_SetCrosshair(0)
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		IIFS EDCBA 1
		TNT1 A 1 A_TakeInventory("RifleSelected", 1)
		TNT1 A 0 A_Lower
		Wait

	Ready:
		TNT1 A 0 A_JumpIfInventory("JustStartedGame",1,"WarmUp")
		TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
		TNT1 A 0 A_PlaySound("CLIPIN")
	Ready1:
		IIFS ABCDE 1
	Ready2:
		TNT1 A 0 //A_GunFlash
	Ready3:
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"ReadyZoom")
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		TNT1 A 0 A_JumpIfInventory("Taunting",1,"Taunt")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"Unload")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		IIFG A 1 A_WeaponReady
		Loop

	ReadyZoom:
		TNT1 A 0 A_JumpIfInventory("Kicking",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Taunting",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"ZoomOut")
		II2G A 1 A_WeaponReady
		Loop
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",1,4)
		TNT1 A 0 A_JumpIfInventory("Clip2",1,3)
		II2G A 1 A_WeaponReady(WRF_NOSECONDARY)
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut
		TNT1 A 0 A_WeaponReady(WRF_NOSECONDARY)
		II2G A 1 A_JumpIfInventory("FiredPrimary",1,"Fire")
		TNT1 A 0 A_JumpIfInventory("FiredSecondary",1,"ReadyZoom")
		Goto ZoomOut
		
// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------
		
	Fire:
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",1,3)
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto DryFire
		TNT1 A 0
		Goto Reload
		TNT1 A 0 A_JumpIfInventory("AmmoCEll", 1, "ElecFire")
		TNT1 A 0 A_PlaySound("HMGFIRE",1)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundRifle", random(-1,1), 0, 0, -12, 0, random(-1,1))
		TNT1 A 0 A_FireCustomMissile("GunFireSmoke", 0, 0, 0, 0, 0, 0)
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
		TNT1 A 0 A_Takeinventory("ElecRifleAmmo",1)
		TNT1 A 0 A_AlertMonsters		
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"FireZoom")
		IIFF F 1 BRIGHT A_FireBullets (2, 2, 1, 20, "HitPuff", FBF_NORANDOM)
		TNT1 A 0 A_FireCustomMissile("DecorativeTracer", frandom(-1.0,1.0), 0, 0, -12, 0, frandom(-1.0,1.0))
		Goto AfterFire+1
		
	ElecFire:
		TNT1 A 0 A_PlaySound("HMGFIRE",1)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundRifle", random(-1,1), 0, 0, -12, 0, random(-1,1))
		TNT1 A 0 A_FireCustomMissile("GunFireSmoke", 0, 0, 0, 0, 0, 0)
		TNT1 A 0 A_FireCustomMissile("BlueFlareSpawn",-5,0,0,0)
		TNT1 A 0 A_Takeinventory("ElecRifleAmmo",1)
		TNT1 A 0 A_TakeInventory("Ammocell", 1)
		TNT1 A 0 A_AlertMonsters		
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"FireZoom")
		TNT1 A 0 A_Jump (256,"fire1", "fire2", "fire3", "fire4" )
	Fire1:
		IIFF B 1 BRIGHT A_FireBullets(1.6, 1.6, -1, 10, "LightningHitPuff")
		Goto AfterFire
	Fire2:
		IIFF C 1 BRIGHT	A_FireBullets(1.6, 1.6, -1, 10, "LightningHitPuff")
		Goto AfterFire
	Fire3:
		IIFF D 1 BRIGHT	A_FireBullets(1.6, 1.6, -1, 10, "LightningHitPuff")
		Goto AfterFire
	Fire4:
		IIFF E 1 BRIGHT A_FireBullets(0, 0, -1, 10, "LightningHitPuff")
		TNT1 A 0 A_FireCustomMissile ("LightningMissile5",0,0,0,5)
		Goto AfterFire
	AfterFire:
		TNT1 A 0 A_FireCustomMissile("BlueDecorativeTracer", frandom(-1.0,1.0), 0, 0, -6, 0, frandom(-1.0,1.0))
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
		TNT1 A 0 A_SetPitch(-1.4 + pitch)
		IIFF G 1 A_ZoomFactor(0.99)
		TNT1 A 0 A_SetPitch(+0.5 + pitch)
		IIFF H 1 A_FireCustomMissile("ElectroCaseSpawn",5,0,4,-10)
		TNT1 A 0 A_SetPitch(+0.3 + pitch)
		IIFG A 1 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetPitch(+0.1 + pitch)
		TNT1 A 0 A_Refire
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner11",0,0,0,0)
		IIFG A 1 A_WeaponReady
		Goto Ready2

	FireZoom:
		TNT1 A 0 A_JumpIfInventory("AmmoCEll", 1, "ElecFireZoom")
		II2F B 1 BRIGHT A_FireBullets (1, 1, 1, 19, "HitPuff", FBF_NORANDOM)
        TNT1 A 0 BRIGHT A_FireCustomMissile("DecorativeTracer", 0, 0, 0, 0)
		Goto AfterFireZoom+1
	ElecFireZoom:
		TNT1 A 0  A_Jump (256,"firezoom1", "firezoom2", "firezoom3")
	firezoom1:
		II2F B 1 BRIGHT A_FireBullets (0.8, 0.8, -1, 10, "LightningHitPuff")
		Goto AfterFireZoom
	firezoom2:
		II2F C 1 BRIGHT	A_FireBullets (0.8, 0.8, -1, 10, "LightningHitPuff")
		Goto AfterFireZoom
	firezoom3:
		II2F D 1 BRIGHT	A_FireBullets (0, 0, -1, 10, "LightningHitPuff")
		TNT1 A 0 A_FireCustomMissile ("LightningMissile5",0,0,0,5)
		Goto AfterFireZoom
	AfterFireZoom:
		TNT1 A 0 A_FireCustomMissile("BlueDecorativeTracer", frandom(-0.5,0.5), 0, 0, -6, 0, frandom(-0.5,0.5))
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle1",30,0,45)
		TNT1 A 0 A_SetPitch(-1.4 + pitch)
		II2F D 1 A_ZoomFactor(1.48)
		TNT1 A 0 A_SetPitch(+0.5 + pitch)
		II2F E 1 A_FireCustomMissile("ElectroCaseSpawn",5,0,4,-4)
		TNT1 A 0 A_SetPitch(+0.3 + pitch)
		II2G A 1 A_ZoomFactor(1.5)
		TNT1 A 0 A_SetPitch(+0.1 + pitch)
		TNT1 A 0 A_ReFire
		TNT1 A 0 A_FireCustomMissile("SmokeSpawner11",0,0,0,0)
		II2G A 1 A_WeaponReady
		Goto ReadyZoom

	AltFire:
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"ZoomOut")
		TNT1 A 0 A_Giveinventory("Zoomed",1)
		TNT1 A 0 A_Giveinventory("ADSmode",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_ZoomFactor(1.5)
		IIFZ ABCD 1
		II2G A 0 A_SetCrosshair(41)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 2 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 0 A_JumpIfInventory("FiredSecondary",1,"HoldAim")
		Goto ReadyZoom
		
	HoldAim:
		II2G A 0
	    "####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
		"####" A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"####" A 0 A_JumpIfInventory("FiredSecondary",1,"HoldAim")

	ZoomOut:
		TNT1 A 0 A_ClearReFire
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetCrosshair(0)
		IIFZ DCBA 1
		Goto Ready2


// --------------------------------------------------------------------------
//
//	Reload n Unload
//
// --------------------------------------------------------------------------

	Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",41,"Ready2") //Check if weapon is full already.
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1) //Check if we have spare ammo.
		Goto Ready2
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"TurboReloadLoop")
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2) //Check if zoomed
		TNT1 A 0 A_Jump(256, 7)
		IIFZ CBA 1
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetCrosshair(0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		IIFR ABCDEFFFFGGHIJK 1
		TNT1 A 0 A_PlaySound("Reload")
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",1,"Reload2") //Check if there is any bullet left in the magazine.
		TNT1 A 0 A_JumpIfInventory("HasUnloaded_PRifle", 1, 2) //Check if weapon has a magazine.
		TNT1 A 0 A_FireCustomMissile("EmptyElecClipSpawn",-5,0,8,-4)
		IIFR LLMN 2
		IIFR OPPS 4
		IIFR TUVWXXYYYYZ 1
		I1FR Z 1
		IIFR EDCBA 1
		/*
		RIFT A 5
		TNT1 A 0 A_PlaySound("SLAPBABY")
		RIFT BCD 1
		RIFT E 4
		RIFT FGHIJK 2
		RIFR RST 1
		*/
		Goto ReloadLoop
	Reload2:
		IIFR LLMN 2
		IIFR OPPS 4
		IIFR TUVWXXYYYYZ 1
		I1FR Z 1
		IIFR EDCBA 1
		Goto ReloadLoop2

	TurboReloadLoop:
	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",40,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("ElecRifleAmmo",1)
		TNT1 A 0 A_Takeinventory("Clip2",1)
		Loop

	ReloadLoop2:
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",41,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("ElecRifleAmmo",1)
		TNT1 A 0 A_Takeinventory("Clip2",1)
		Loop
		
	ReloadDone:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("HasUnloaded_PRifle", 1)
		TNT1 A 0 A_Refire
		Goto Ready2
		
	Unload:
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",1,1)
		Goto Ready2
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2) //Check if zoomed
		TNT1 A 0 A_Jump(256, 7)
		IIFZ CBA 1
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_SetCrosshair(0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		IIFG A 1
		IIFR TSRQPO 1
		TNT1 A 0 A_PlaySound("Reload")
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		Goto UnloadLoop

	UnloadLoop:
		TNT1 A 0 A_JumpIfInventory("ElecRifleAmmo",1,1)
		Goto UnloadDone
		TNT1 A 0 A_Takeinventory("ElecRifleAmmo",1)
		TNT1 A 0 A_Giveinventory("Clip2",1)
		Loop

	UnloadDone:
		IIFR NMLKIGHGFEDCBA 1
		TNT1 A 0 A_GiveInventory("HasUnloaded_PRifle", 1)
		Goto Ready2

// --------------------------------------------------------------------------
//
//	Misc.
//
// --------------------------------------------------------------------------
	/*
	DualWield:
		TNT1 A 0 A_Takeinventory("StartDualWield",1)
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1028)==0, "NoDualWield")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1028)==2, "Ready2")
		TNT1 A 0 A_JumpIfInventory("TE_Rifles",2,2)
		TNT1 A 0 A_Print("You must have two rifles to dual wield.")
		Goto Ready2
		RIFS ABCDE 1
		TNT1 A 6
		TNT1 A 0 A_Takeinventory("StartDualWield",1)
		TNT1 A 0 A_Giveinventory("PowerSphere2",1)
		Goto Ready
	*/
	NoDualWield:
		TNT1 A 0 A_Print("Dual wielding is disabled.")
		Goto Ready2

	DryFire:
		TNT1 A 0 A_PlaySound("weapons/empty", 5)
		Goto Ready2

	Steady:
		TNT1 A 1
		Goto Ready

	WarmUp:
		TNT1 A 0 A_TakeInventory("JustStartedGame", 1)
		TNT1 A 10 A_WeaponReady
		PUNS ABCD 1 A_WeaponReady
		TNT1 A 0 A_PlaySound("Knuckled")
		PUNS E 7 A_WeaponReady
		PUNS FGFE 3 A_WeaponReady
		PUNS DCB 1 A_WeaponReady
		TNT1 A 10 A_WeaponReady
		Goto Ready
	/*
	Execution2:
		TNT1 A 0 A_ZoomFactor(1.1)
		RIBB A 1 A_Stop
        RIBB B 1 A_PlaySound("skeleton/swing")
		RIBB C 1 A_FireCustomMissile("ExecutionAttackMelee", 0, 0, 0, 0)
		RIBB D 6 A_Stop
		RIBB CBA 2 A_Stop
		RIBB A 1 A_Stop
        RIBB B 1 A_PlaySound("skeleton/swing")
		RIBB C 1 A_FireCustomMissile("ExecutionAttackMelee", 0, 0, 0, 0)
		RIBB D 6 A_Stop
		RIBB CBA 2 A_Stop
		RIBB A 1 A_Stop
        RIBB B 1 A_PlaySound("skeleton/swing")
		RIBB C 1 A_FireCustomMissile("ExecutionAttackKick", 0, 0, 0, 0)
		RIBB D 6 A_Stop
		RIBB CBA 2 A_Stop
		TNT1 A 5
		Goto FinishExecution	
	*/
// --------------------------------------------------------------------------
//
//	End stuff
//
// --------------------------------------------------------------------------

	TauntFlash:
		IIFK ABCDE 1
		IIFK E 33
		IIFK EDCBA 1
		IIFG A 1
		Stop

	KickFlash:
		IIFK ABCD 1
		IIFK E 8
		IIFK DCBA 1
		IIFG A 1
		Stop

	AirKickFlash:
		IIFK ABCD 1
		IIFK E 10
		IIFK DCBA 1
		IIFG A 1
		Stop
		
	SlideKickStartFlash:
		IIFK ABCD 1
		IIFK E 17
		Stop
	
	SlideKickEndFlash:
		IIFK E 6
		IIFK DCBA 1
		IIFG A 1
		Stop

	GrenadeFlash:
		IIFS ABCDE 1
		Stop
	}
}
ACTOR ElecRifleAmmo : Ammo
{
	+INVENTORY.IGNORESKILL
	Inventory.Amount 0
	Inventory.MaxAmount 41
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 41
   	Inventory.Icon "IRIFA0"
}
ACTOR HasUnloaded_PRifle : Inventory { Inventory.MaxAmount 1 }

ACTOR LightningHitPuff : HitPuff
{
	renderstyle Add
	alpha 0.3
	Scale 0.8
	radius 0
	height 0
	+NOBLOCKMAP
	+NOGRAVITY
	+NOEXTREMEDEATH
	+FORCEXYBILLBOARD
	+DONTSPLASH
	-EXPLODEONWATER
	Gravity 0.01
	DamageType Bullet
	Decal "BulletDecalNew1"
  states
  {
  Spawn:
    TNT1 A 0
	TNT1 A 0 A_SpawnItemEx ("BlueRicoChet",0,0,-5,0,0,0,0,SXF_NOCHECKPOSITION,0)
  Melee:
	TNT1 A 0 A_jump(96,2)
	TNT1 A 0 A_SpawnItemEx ("StunLightningsSmall",0,0,0,0,0,0,random(-180,180),SXF_NOCHECKPOSITION,0)
	TNT1 A 1
	stop
	
  }
}